package com.zw.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zw.dto.RegisterDto;
import com.zw.entity.SysRole;
import com.zw.service.SysRoleService;
import com.zw.utils.CopyUtils;
import com.zw.vo.GetAllRolesVO;
import com.zw.vo.ResponseVO;
import io.jsonwebtoken.lang.Collections;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 角色信息表(SysRole)表控制层
 *
 * @author makejava
 * @since 2025-03-14 17:50:09
 */
@RestController
@RequestMapping("sysRole")
@Api(value = "角色信息API", tags = "角色信息API")
public class SysRoleController {


    /**
     * 服务对象
     */
    @Resource
    private SysRoleService sysRoleService;


    /**
     * 获取角色列表

     * @return 结果
     */
    @ApiOperation("获取角色列表")
    @GetMapping("/getAllRoles")
    public ResponseVO<List<GetAllRolesVO>> getAllRoles() {
        try {
            List<GetAllRolesVO> resList = new ArrayList<>();
            List<SysRole> list = sysRoleService.list(new QueryWrapper<SysRole>().lambda()
                    .eq(SysRole::getRoleId,3)
                    .eq(SysRole::getDelFlag,0));
            if (!Collections.isEmpty(list)){
                resList = CopyUtils.copyList(list,GetAllRolesVO.class);
            }
            return new ResponseVO(resList);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("获取角色列表失败，请联系管理员处理！");
        }
    }

}

